<?php

class User extends Controller
{
	function __construct()
	{
		parent::Controller();
		$this->load->model('user_model');
	}
	
	function User()
	{
		self::__construct();
	}
	
	function index()
	{
        if ($this->quickauth->logged_in() == FALSE)
        {
            redirect('administration/login');
        }
        else
        {
            redirect('administration/dashboard');
        }
		
	}
	
	function settings()
	{
		$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
		
		if($this->form_validation->run('user_settings') === TRUE)
		{
			$password = sha1($this->config->item('encryption_key').$this->input->post('user_password'));
			
			$userdata2 = array(
								'password' => $password,
								'email' => $this->input->post('user_email')
							);
			
			$this->db->where('username', $_SESSION['username']);
			$this->db->update('users', $userdata2);
			
			$recent = array(
							'username' => $_SESSION['username'],
							'module' => 'settings',
							'action' => 'Updated user settings'
							);
							
			$this->db->insert('recent', $recent);
			
			$data = array('body_id' => 'settings');
			
			$data2 = array(
							'title' => 'Changes Made',
							'message' => 'Congratulations, your details have now been updated..'
						);
			
			$this->load->view('header', $data);
			$this->load->view('message', $data2);
			$this->load->view('footer');
		}
		else
		{			
			$data = array('body_id' => 'settings');
			
			$user = $this->user_model->get_user();
			
			$userdata['user'] = $user;
			
			$this->template->load('header', $data);
			$this->template->load('edit_settings', $userdata);
			$this->template->load('footer');
		}
	} // settings()
	
	function logout()
	{
		$this->auth->logout();
	}
	
	function register()
	{
		$this->auth->register();
	}
	
}

/* End of file user.php */
/* Location: modules/user/controllers/login.php */